const { ProductActivity } = require('@/models/product');
const getPromotions = async (req, res) => {
  try {
    const { offset, limit } = req.query;
    const { rows, total } = await ProductActivity.getPromotions(offset, limit);
    res.json({ rows, total });
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const createPromotion = async (req, res) => {
  try {
    const data = req.body;
    const promotion = await ProductActivity.createPromotion(data);
    res.json(promotion);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const updatePromotion = async (req, res) => {
  try {
    const { id } = req.params;
    const data = req.body;
    const promotion = await ProductActivity.updatePromotion(id, data);
    res.json(promotion);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const updateStatus = async (req, res) => {
  try {
    const { id } = req.params;
    const data = req.body;
    const promotion = await ProductActivity.updateStatus(id, data);
    res.json(promotion);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const getParticipation = async(req, res) => {
  try {
    const { id } = req.params;
    const participation = await ProductActivity.getParticipation(id);
    res.json(participation);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}
const applyPromotion = async (req, res) => {
  try {
    const { id } = req.params;
    const data = req.body;
    const promotion = await ProductActivity.applyPromotion(id, data);
    res.json(promotion);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
}

module.exports = {
  getPromotions,
  createPromotion,
  updatePromotion,
  updateStatus,
  getParticipation,
  applyPromotion
}